package com.example.tliaswebmanagement.service.impl;

import com.example.tliaswebmanagement.mapper.EmpMapper;
import com.example.tliaswebmanagement.mapper.StuMapper;
import com.example.tliaswebmanagement.pojo.JobStatistics;
import com.example.tliaswebmanagement.pojo.StuStatistics;
import com.example.tliaswebmanagement.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class ReportServiceImpl implements ReportService {
    private final EmpMapper empMapper;
    private final StuMapper stuMapper;

    public ReportServiceImpl(EmpMapper empMapper, StuMapper stuMapper) {
        this.empMapper = empMapper;
        this.stuMapper = stuMapper;
    }

    /**
     * 统计员工职位人数
     */
    @Override
    public JobStatistics getEmpJobData() {
        // 1. 调用 Mapper 接口，获取统计数据
        List<Map<String, Object>> list = empMapper.countEmpJobData();
        // 2. 组装结果并返回
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();

        return new JobStatistics(jobList, dataList);
    }

    /**
     * 统计不同性别的人数
     */
    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.getEmpGenderData();
    }

    /**
     * 统计每一个班的人数
     */
    @Override
    public StuStatistics getStuData() {
        // 1. 调用 Mapper 接口， 获取数据
        List<Map<String, Object>> list = empMapper.countStuData();
        // 2. 封装结果并返回（注意 get 里面的名称要和 Mybatis 里的 SQL 语句起的名字要对应才能封装上）
        List<Object> clazzList = list.stream().map(dataMap -> dataMap.get("clazzList")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("dataList")).toList();

        return new StuStatistics(clazzList, dataList);
    }

    /**
     * 统计学员学历分布
     */
    @Override
    public List<Map<String, Object>> getDegreeData() {
        return stuMapper.getDegreeData();
    }
}
